package com.sfh.cpc.note;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sfh.cpc.BaseSwipeRefreshMoreLayoutFragment;
import com.sfh.cpc.R;
import com.sfh.cpc.com.entity.EMass;
import com.sfh.cpc.com.entity.ENote;
import com.sfh.cpc.com.entity.RspPage;
import com.sfh.cpc.com.entity.RxEventSearch;
import com.sfh.cpc.com.refresh.SwipeRefreshMoreLayout;
import com.sfh.cpc.home.adapter.NoteAdapter;
import com.sfh.cpc.mass.MassSearchFragment;
import com.sfh.cpc.mass.model.MassModel;
import com.sfh.cpc.note.model.NoteModel;
import com.sfh.lib.event.RxBusEvent;
import com.sfh.lib.mvvm.annotation.LiveDataMatch;
import com.sfh.lib.ui.AbstractLifecycleFragment;

/**
 * 功能描述:搜索贴子
 *
 * @author SunFeihu 孙飞虎
 * @date 2019/6/11
 */
public class SearchNoteFragment extends BaseSwipeRefreshMoreLayoutFragment<NoteModel> {

    public static SearchNoteFragment newFragment() {
        return new SearchNoteFragment();
    }

    private String content = "";

    @Override
    public String getName() {
        return "帖子";
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        onAutoRefresh = false;
        return new NoteAdapter();
    }

    @Override
    public void loadPage(int nowPage) {
        this.activateLifecycleEvent();
        this.getViewModel().querySearchNote(nowPage, content);
    }


    @RxBusEvent(from = "搜索")
    public void onRxEventSearch(RxEventSearch data) {
        content = data.content;
        swipeRefreshMoreLayout.onAutoRefresh();
    }

    @LiveDataMatch
    public void onPageSuccess(RspPage<ENote> data) {

        super.onPageData(data);
    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        ENote note = (ENote) adapter.getItem(position);
        NoteActivity.startUI(getContext(), note);
    }
}
